﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary1;

namespace WebApplication1
{
    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Panel2.Visible = false;
            Panel3.Visible = false;
            Label1.Text = DateTime.Today.DayOfWeek.ToString();
            Label2.Text = DateTime.Now.ToShortDateString();
            if (Session["user"] != null)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
                Panel3.Visible = true;
                Label5.Text = "Hi " + Session["user"].ToString()+" ,wellcome you ! If you want to log out,click  ";
            }
        }

        public void showMessage(string mess)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "alert", "<script language='javascript'>alert('" + mess + "')</script>", false);
        }


        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["user"] != null)
            {
                Session.Remove("user");
                Response.Redirect("Homes.aspx");
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Users user = new Users();
            bool flag = user.CheckLogin(TextBox1.Text, TextBox2.Text);
            if (flag)
            {
                HttpCookie cookie = new HttpCookie("cookie");
                Response.Cookies.Remove("cookie");
                Response.Cookies.Add(cookie);
                cookie.Values.Add("user", TextBox1.Text);
                cookie.Values.Add("pass", TextBox2.Text);
                if (cbRemember.Checked)
                {

                    Response.Cookies["cookie"].Expires = DateTime.Now.AddDays(5);
                }
                else
                {
                    Response.Cookies["cookie"].Expires = DateTime.Now;
                }
                Session["user"] = TextBox1.Text;
                Session["pass"] = TextBox2.Text;
                Response.Redirect("Index.aspx");
            }
            else
            {
                showMessage("Incorrect UserID or password!");
            }
        }
    }
}
